package com.zhaotianhao.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.zhaotianhao.mapper.GoodsMapper;
import com.zhaotianhao.pojo.From;
import com.zhaotianhao.pojo.Goods;
import com.zhaotianhao.service.GoodsService;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * (Goods)表服务实现类
 *
 * @author Z-7
 * @since 2022-02-23 14:22:21
 */
@DubboService(loadbalance = "random",weight = 40)
public class GoodsServiceImpl implements GoodsService {
    @Autowired
    private GoodsMapper goodsMapper;

    /**
     * 通过ID查询单条数据
     *
     * @param id 主键
     * @return 实例对象
     */
    @Override
    public Goods queryById(Integer id) {
        return this.goodsMapper.queryById(id);
    }

    /**
     * 分页查询
     *
     * @param goods 筛选条件
     * @param pageNum 起始页数
     * @param pageSize 分页偏移量
     * @return 查询结果
     */
    @Override
    public From queryByPage(Goods goods,int pageNum,int pageSize) {
        PageHelper.startPage(pageNum,pageSize);
        System.err.println("这是服务二=============");
        PageInfo<Goods> page = new PageInfo<>(this.goodsMapper.queryAll(goods));
        return new From().setPageInfo(page).setCome("服务二");
    }

    /**
     * 新增数据
     *
     * @param goods 实例对象
     * @return 影响行数
     */
    @Override
    public int insert(Goods goods) {
        return this.goodsMapper.insert(goods);
    }

    /**
     * 修改数据
     *
     * @param goods 实例对象
     * @return 影响行数
     */
    @Override
    public int update(Goods goods) {
        return this.goodsMapper.update(goods);
    }

    /**
     * 通过主键删除数据
     *
     * @param id 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Integer id) {
        return this.goodsMapper.deleteById(id) > 0;
    }
}
